package com.zhixiang.xaec.action.safebase.weixianzuoye;


import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.zhixiang.core.command.QueryFilter;
import com.zhixiang.core.util.String2Array;
import com.zhixiang.core.web.action.BaseAction;
import com.zhixiang.xaec.entity.safebase.weixianzuoye.WeiXianZuoYePingGu;
import com.zhixiang.xaec.service.safebase.weixianzuoye.WeiXianZuoYePingGuService;


@Controller
public class WeiXianZuoYePingGuAction extends BaseAction
{

    /**
     * 意义，目的和功能，以及被用到的地方<br>
     */
    private static final long serialVersionUID = -1918755284712602180L;

    @Autowired
    private WeiXianZuoYePingGuService weiXianZuoYePingGuService;

    private WeiXianZuoYePingGu weiXianZuoYePingGu;

    /**
     * @return Returns the weiXianZuoYePingGu.
     */
    public WeiXianZuoYePingGu getWeiXianZuoYePingGu()
    {
        return weiXianZuoYePingGu;
    }

    /**
     * @param weiXianZuoYePingGu
     *            The weiXianZuoYePingGu to set.
     */
    public void setWeiXianZuoYePingGu(WeiXianZuoYePingGu weiXianZuoYePingGu)
    {
        this.weiXianZuoYePingGu = weiXianZuoYePingGu;
    }

    public String list()
    {
        QueryFilter localQueryFilter = new QueryFilter(getRequest());
        List<WeiXianZuoYePingGu> list = weiXianZuoYePingGuService.getAll(localQueryFilter);
        setTotalCounts(localQueryFilter.getPagingBean().getTotalItems());
        setResult(list);
        return SUCCESS;
    }

    public String get()
    {
        String id = getRequest().getParameter("id");
        if (StringUtils.isNotEmpty(id))
        {
            setResult(weiXianZuoYePingGuService.get(Long.valueOf(id)));
        }
        return SUCCESS;
    }

    public String delete()
    {
        try
        {
            String ids[] = getRequest().getParameterValues("ids");
            Long[] longIds = String2Array.stringArrayToLongArray(ids);
            weiXianZuoYePingGuService.remove(longIds);
        }
        catch (Exception e)
        {
            setMsg("删除失败");
            setSuccess(false);
        }
        return SUCCESS;
    }

    public String save()
    {
        try
        {
            weiXianZuoYePingGuService.save(weiXianZuoYePingGu);
        }
        catch (Exception e)
        {
            setMsg("保存失败");
            setSuccess(false);
        }

        return SUCCESS;
    }

}
